﻿using CKS.Core.Framework;
using Microsoft.Extensions.DependencyInjection;
using Infrastructure;

using Microsoft.Extensions.Logging;
using CKS.PLC.Action.Subscription.OP10;

namespace CKS.PLC.Action.OP10
{
    /// <summary>
    /// 动作编号1 ，处理错误
    /// 主界面需要展示错误页，收到重置状态后，隐藏错误页
    /// 
    /// </summary>
    public class Cks204Action : LoadingActionBase
    {
        public Cks204Action(DecodeValue _value) : base(_value)
        {
        }

        public override void Execute()
        {
            var result = Value.Value.ToInt();
            int replayDB = 3010;
            int replayAction = 204;

            if (result == 1)
            {

                string bluecode = Value.GetLinkData(1).ToString();
                ProccessLoading(replayDB, replayAction, bluecode);
                EventBus.AddLog($"OP10-L4请求上料 {bluecode}");
            }
            else
            {
                var needTypePos = Value.GetPosition(replayDB, replayAction, 2);
                var replayPos = Value.GetPosition(replayDB, replayAction, 1);

                AckWriteInt16(needTypePos, 0);
                AckWriteInt16(replayPos, 0);
                EventBus.AddLog($"OP10-L4请求上料 重置保存状态");
            }
        }
    }
}
